package logic

import (
	"context"
	"shop/models/mysql"

	"shop/shoprpc/internal/svc"
	"shop/shoprpc/shoprpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderListLogic {
	return &OrderListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderListLogic) OrderList(in *shoprpc.OrderListRequest) (*shoprpc.OrderListResponse, error) {
	// todo: add your logic here and delete this line
	var orders []mysql.Order
	mysql.DB.Debug().Find(&orders)

	var OrderList []*shoprpc.OrderList
	for _, order := range orders {
		list := shoprpc.OrderList{
			UserId:   int64(order.UserId),
			Status:   int64(order.Status),
			PayTypes: int64(order.PayTypes),
			Price:    float32(order.Price),
			Total:    float32(order.Total),
			Number:   int64(order.Number),
		}
		OrderList = append(OrderList, &list)
	}
	return &shoprpc.OrderListResponse{
		List: OrderList,
	}, nil
}
